<template>
  <div class="search">
    <f-form ref="form" :action="api.shop" :form-key="this.formItem.shopId">
      <f-form-item label="店铺简介" name="shopDesc" type="editor" :value="formItem.shopDesc"/>
      <f-form-item label="店铺动态" name="shopDynamic" type="textarea" :value="formItem.shopDynamic"/>
      <f-form-item label="营业范围" name="businessScope" type="textarea" :value="formItem.businessScope"/>
      <f-form-item label="店铺门头" type="upload" name="shopDoorway" :value="formItem.shopDoorway" @uploadSuccess="uploadSuccess"/>
      <f-form-item label="店铺视频" type="video" name="shopVideo" :value="formItem.shopVideo" @uploadSuccess="uploadVideoSuccess"/>
    </f-form>
  </div>
</template>

<script>
  export default {
    name: 'shopDesc',
    props: {},
    data() {
      return {
        isAdd: true,
        loaded: false,
        fileIds: [],
        removeIds: [],
        videoId: '',
        formItem: this.getFormItem()
      }
    },
    methods: {
      getFormItem() {
        return {
          shopName: '',
          shopDoorway: '',
          shopDynamic:'',
          businessScope:'',
          shopVideo: ''
        }
      },
      //门头上传回调
      uploadSuccess(fileUrl, files, fileIds, removeIds) {
        this.formItem.shopDoorway = fileUrl
        this.removeIds.push(...removeIds)
      },
      uploadVideoSuccess(fileUrl, file, fileId, removeIds) {
        this.videoId = fileId
        this.product.productVideo = fileUrl
        this.removeIds.push(...removeIds)
      },
      setData(data) {
        this.$refs.form.resetFields()
        if (data && data.shopId) {
          this.$refs.form.getDetails({ shopId: data.shopId }, (data) => {
            this.formItem = data
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.formItem = this.getFormItem()
          this.loaded = true
        }
      },
      handleSubmit(callback) {
        if (this.videoId) {
          this.fileIds.push(this.videoId)
        }
        this.$refs.form.submit({
          removeIds: this.removeIds.join(','),
          fileIds: this.fileIds.join(',')
        }, callback)
      }
    },
    created() {

    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
